﻿using Eps.Ai.Common;
using InfonavaEye.Forms;
using InfonavaEye.handler;
using InfonavaEye.Handler;
using InfonavaEye.util;
using Sylan.Common.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InfonavaEye
{
    public partial class IndexForm : Form
    {
       
        public IndexForm()
        {
            InitializeComponent();
            //this.checkMac();
        }

        /// <summary>
        /// 检查本机MAC地址是否正确
        /// </summary>
        private void checkMac()
        {
            var mac = SystemInfoHelper.getMacAddr_Local();
            Console.WriteLine("Config.DEVICE_SN", Config.DEVICE_SN);
            Console.WriteLine("Config.DEVICE_MODEL", Config.DEVICE_MODEL);
            Console.WriteLine("Config.DEVICE_MAC", Config.DEVICE_MAC);
            if (!mac.Equals(Config.DEVICE_MAC))
            {
                MessageBox.Show("检测到非法使用本程序，请联系程序的所有者");
                System.Environment.Exit(0);
            }
        }

        private void pictureBox2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void IndexForm_Load(object sender, EventArgs e)
        {
            
            //this.WindowState = FormWindowState.Maximized;


            /*ThreadHelper.ExcuteThreadTask(() =>
            {
                startHttpsBoltStraight();
            }, 250);*/

            //磁盘检测
            Task.Factory.StartNew(() =>
            {
                this.checkDiskSize();
            });
        }


        private void IndexForm_FormClosing(object sender, FormClosingEventArgs e)
        {
           
        }

        private string exePath = null;
        private void startHttpsBoltStraight()
        {
            exePath = util.FileHelper.getBaseDir() + "\\socket_multi_process_server\\socket_multi_process_server.exe";
            ExeUtil.openExe(exePath, "圆型图片拉直");
        }

        private void checkDiskSize()
        {
            long freeSpace = GetHardDiskFreeSpace("D");
            string baseDir = util.FileHelper.getBaseDir() + "\\Image";
            if (freeSpace < Config.MAX_HARD_DISK_FREE_SPACE)
            {
                MessageBox.Show(String.Format("检测到电脑的D盘控件只剩下{0}G了，请清理不再需要的文件,位置在：{1}。", freeSpace, baseDir));
            }
        }

        /// <summary>
        /// 获取指定驱动器的剩余空间总大小(单位为GB)
        /// </summary>
        /// <param name="str_HardDiskName"></param>
        /// <returns>GB</returns>        
        private long GetHardDiskFreeSpace(string str_HardDiskName)
        {
            long freeSpace = new long();
            str_HardDiskName = str_HardDiskName + ":\\";
            System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
            foreach (System.IO.DriveInfo drive in drives)
            {
                if (drive.Name == str_HardDiskName)
                {
                    freeSpace = drive.TotalFreeSpace / (1024 * 1024 * 1024);
                }
            }
            return freeSpace;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            ManualCaptureForm mainForm = new ManualCaptureForm();
            mainForm.Show();
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            MainForm mainForm = new MainForm();
            mainForm.Show();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            BoxModelForm form = new BoxModelForm();
            form.ShowDialog();
        }

        private void deviceStatusBox_Click(object sender, EventArgs e)
        {

        }

        private void IndexForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            System.Environment.Exit(0);
        }
    }
}
